package mysql

import (
	"fmt"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
	"zc/rpc/appconfig"
	"zc/rpc/global"
)

func MysqlApp() {
	stu := appconfig.AppCon.MysqlApp
	var err error
	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", stu.Username, stu.Password, stu.Hort, stu.Part, stu.Data)
	global.DB, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		fmt.Println("mysql 连接失败", err)
		return
	}
	fmt.Println("mysql 连接成功")
	global.DB.AutoMigrate(new(Video))
}
